import http from "@/api";

import { PORT1 } from "@/api/config/servicePort";

// 路由枚举
export const enum RouteType {
  consumer = "consumer", //消费品
  industrial = "industrial", //工业品
  food = "food" //食品
}

// 标签页枚举
export const enum TabType {
  // 企发销售属性
  sales = "sales",
  // 清关属性
  clearance = "clearance"
}

// 树结构类型
export interface TreeType {
  id?: string;
  value: string | number;
  label: string;
  childs?: TreeType[];
}

// 下拉选项类型
export interface OptionType {
  key: string | number;
  value: string;
}

// 标准下拉选项类型
export interface StandOptionType {
  value: string | number;
  label: string;
}

// 属性列表行数据类型
export interface AttributeType {
  propvalue_id: number;
  propvalue: string;
  propvalue_cn: string;
}

// 清关属性枚举路径 上传
export const UploadClearPath ={
  [RouteType.consumer]:"/goods-config/consumerProperty/edit-ccprop/upload",//消费品
    [RouteType.industrial]:"/goods-config/mroProperty/edit-ccprop/upload",//工业品
    [RouteType.food]:"/goods-config/foodProperty/edit-ccprop/upload",//食品

}

// 清关属性枚举路径 上传
export const UploadPath ={
  [RouteType.consumer]:"/goods-config/consumerProperty/sale-property-update/upload",//消费品
    [RouteType.industrial]:"/goods-config/mroProperty/sale-property-update/upload",//工业品
    [RouteType.food]:"/goods-config/foodProperty/sale-property-update/upload",//食品

}

// 树结构路径
const TreePath = {
  [RouteType.consumer]: "/goods-config/consumerProperty/sale-property/type-tree", //消费品
  [RouteType.industrial]: "/goods-config/mroProperty/sale-property/type-tree", //工业品
  [RouteType.food]: "/goods-config/foodProperty/sale-property/type-tree" //食品
};

// 销售属性表头路径
export const SalesHeaderPath = {
  [RouteType.consumer]: "/goods-config/consumerProperty/sale-property", //消费品
  [RouteType.industrial]: "/goods-config/mroProperty/sale-property", //工业品
  [RouteType.food]: "/goods-config/foodProperty/sale-property" //食品
};

// 销售属性表格路径
export const SalesTablePath = {
  [RouteType.consumer]: "/goods-config/consumerProperty/sale-property", //消费品
  [RouteType.industrial]: "/goods-config/mroProperty/sale-property", //工业品
  [RouteType.food]: "/goods-config/foodProperty/sale-property" //食品
};

// 销售属性值列表路径
const SalesAttributeListPath = {
  [RouteType.consumer]: "/goods-config/consumerProperty/sale-property/enum-values", //消费品
  [RouteType.industrial]: "/goods-config/mroProperty/sale-property/enum-values", //工业品
  [RouteType.food]: "/goods-config/foodProperty/sale-property/enum-values" //食品
};

// 删除销售属性路径
const DeleteSalesPropertyPath = {
  [RouteType.consumer]: "/goods-config/consumerProperty/sale-property/delete", //消费品
  [RouteType.industrial]: "/goods-config/mroProperty/sale-property/delete", //工业品
  [RouteType.food]: "/goods-config/foodProperty/sale-property/delete" //食品
};

// 销售属性商品类型路径
const SalesProductType = {
  [RouteType.consumer]: "/goods-config/consumerProperty/sale-property-update/goods-type", //消费品
  [RouteType.industrial]: "/goods-config/mroProperty/sale-property-update/goods-type", //工业品
  [RouteType.food]: "/goods-config/foodProperty/sale-property-update/goods-type" //食品
};

// 销售属性商品属性路径
const SalesGoodsAttribute = {
  [RouteType.consumer]: "/goods-config/consumerProperty/sale-property-update/get-prop", //消费品
  [RouteType.industrial]: "/goods-config/mroProperty/sale-property-update/get-prop", //工业品
  [RouteType.food]: "/goods-config/foodProperty/sale-property-update/get-prop" //食品
};

// 复制销售属性路径
const SalesCopyGoodsAttribute = {
  [RouteType.consumer]: "/goods-config/consumerProperty/sale-property-update/copy-prop", //消费品
  [RouteType.industrial]: "/goods-config/mroProperty/sale-property-update/copy-prop", //工业品
  [RouteType.food]: "/goods-config/foodProperty/sale-property-update/copy-prop" //食品
};

// 销售属性单元格编辑路径
const SalesEditCellPath = {
  [RouteType.consumer]: "/goods-config/consumerProperty/sale-property-update/editable", //消费品
  [RouteType.industrial]: "/goods-config/mroProperty/sale-property-update/editable", //工业品
  [RouteType.food]: "/goods-config/foodProperty/sale-property-update/editable" //食品
};

// 清关属性表头路径
export const ClearanceHeaderPath = {
  [RouteType.consumer]: "/goods-config/consumerProperty/cc-property", //消费品
  [RouteType.industrial]: "/goods-config/mroProperty/cc-property", //工业品
  [RouteType.food]: "/goods-config/foodProperty/cc-property" //食品
};

// 清关属性表格路径
export const ClearanceTablePath = {
  [RouteType.consumer]: "/goods-config/consumerProperty/cc-property", //消费品
  [RouteType.industrial]: "/goods-config/mroProperty/cc-property", //工业品
  [RouteType.food]: "/goods-config/foodProperty/cc-property" //食品
};

// 清关属性值列表路径
const ClearanceAttributeListPath = {
  [RouteType.consumer]: "/goods-config/consumerProperty/cc-property/enum-values", //消费品
  [RouteType.industrial]: "/goods-config/mroProperty/cc-property/enum-values", //工业品
  [RouteType.food]: "/goods-config/foodProperty/cc-property/enum-values" //食品
};

// 删除销售属性路径
const DeleteClearancePropertyPath = {
  [RouteType.consumer]: "/goods-config/consumerProperty/cc-property/delete", //消费品
  [RouteType.industrial]: "/goods-config/mroProperty/cc-property/delete", //工业品
  [RouteType.food]: "/goods-config/foodProperty/cc-property/delete" //食品
};

// 清关属性商品类型路径
const ClearanceProductType = {
  [RouteType.consumer]: "/goods-config/consumerProperty/edit-ccprop/goods-type", //消费品
  [RouteType.industrial]: "/goods-config/mroProperty/edit-ccprop/goods-type", //工业品
  [RouteType.food]: "/goods-config/foodProperty/edit-ccprop/goods-type" //食品
};

// 清关属性商品属性路径
const ClearanceGoodsAttribute = {
  [RouteType.consumer]: "/goods-config/consumerProperty/edit-ccprop/get-prop", //消费品
  [RouteType.industrial]: "/goods-config/mroProperty/edit-ccprop/get-prop", //工业品
  [RouteType.food]: "/goods-config/foodProperty/edit-ccprop/get-prop" //食品
};

// 复制清关属性路径
const ClearanceCopyGoodsAttribute = {
  [RouteType.consumer]: "/goods-config/consumerProperty/edit-ccprop/copy-prop", //消费品
  [RouteType.industrial]: "/goods-config/mroProperty/edit-ccprop/copy-prop", //工业品
  [RouteType.food]: "/goods-config/foodProperty/edit-ccprop/copy-prop" //食品
};

//企发属性
//新增企发销售属性接口
const AddPath = {
  [RouteType.consumer]: "/goods-config/consumerProperty/sale-property-update/create", //消费品
  [RouteType.industrial]: "/goods-config/mroProperty/sale-property-update/create", //工业品
  [RouteType.food]: "/goods-config/foodProperty/sale-property-update/create" //食品
};
//编辑企发销售属性接口
const EditsPath = {
  [RouteType.consumer]: "/goods-config/consumerProperty/sale-property-update/view", //消费品
  [RouteType.industrial]: "/goods-config/mroProperty/sale-property-update/view", //工业品
  [RouteType.food]: "/goods-config/foodProperty/sale-property-update/view" //食品
};


//企发销售属性下载模版
const downloadTemplatePath = {
  [RouteType.consumer]: "/goods-config/consumerProperty/sale-property-update/generate-excel", ///日用品
  [RouteType.industrial]: "/goods-config/mroProperty/sale-property-update/generate-excel", //工业品
  [RouteType.food]: "/goods-config/foodProperty/sale-property-update/generate-excel" //食品
};

//企发销售属性下载导入失败模版
const downloadFailTemplatePath = {
  [RouteType.consumer]: "/goods-config/consumerProperty/sale-property-update/download-import", ///日用品
  [RouteType.industrial]: "/goods-config/mroProperty/sale-property-update/download-import", //工业品
  [RouteType.food]: "/goods-config/foodProperty/sale-property-update/download-import" //食品
};
 



//清关属性下载模版
const downloadTemplateClearPath = {
  [RouteType.consumer]: "/goods-config/consumerProperty/edit-ccprop/generate-excel", ///日用品
  [RouteType.industrial]: "/goods-config/mroProperty/edit-ccprop/generate-excel", //工业品
  [RouteType.food]: "/goods-config/foodProperty/edit-ccprop/generate-excel" //食品
};

//清关属性下载导入失败模版
const downloadFailTemplateClearPath = {
  [RouteType.consumer]: "/goods-config/consumerProperty/edit-ccprop/download-import", ///日用品
  [RouteType.industrial]: "/goods-config/mroProperty/edit-ccprop/download-import", //工业品
  [RouteType.food]: "/goods-config/foodProperty/edit-ccprop/download-import" //食品
};
 




//新增清关属性接口
const ClearancAddPath = {
  [RouteType.consumer]: "/goods-config/consumerProperty/edit-ccprop/create", //消费品
  [RouteType.industrial]: "/goods-config/mroProperty/edit-ccprop/create", //工业品
  [RouteType.food]: "/goods-config/foodProperty/edit-ccprop/create" //食品
};
// 编辑清关属性接口
const ClearancEditsPath = {
  [RouteType.consumer]: "/goods-config/consumerProperty/edit-ccprop/index", //消费品
  [RouteType.industrial]: "/goods-config/mroProperty/edit-ccprop/index", //工业品
  [RouteType.food]: "/goods-config/foodProperty/edit-ccprop/index" //食品
};

//清关编辑提交  提交第一个模块，表单数据
const saveClearancOnePath = {
  [RouteType.consumer]: "/goods-config/consumerProperty/edit-ccprop/edit-prop", //消费品
  [RouteType.industrial]: "/goods-config/mroProperty/edit-ccprop/edit-prop ", //工业品
  [RouteType.food]: "/goods-config/foodProperty/edit-ccprop/edit-prop " //食品
};
//清关编辑提交  提交第二个模块，表单数据
const saveClearancTwoPath = {
  [RouteType.consumer]: "/goods-config/consumerProperty/edit-ccprop/edit-propval", //消费品
  [RouteType.industrial]: "/goods-config/mroProperty/edit-ccprop/edit-propval", //工业品
  [RouteType.food]: "/goods-config/foodProperty/edit-ccprop/edit-propval" //食品
};

//清关编辑提交  提交第一个模块，表单数据
const saveQifaOnePath = {
  [RouteType.consumer]: "/goods-config/consumerProperty/sale-property-update/update-info", //消费品
  [RouteType.industrial]: "/goods-config/mroProperty/sale-property-update/update-info", //工业品
  [RouteType.food]: "/goods-config/foodProperty/sale-property-update/update-info" //食品
};
//清关编辑提交  提交第二个模块，表单数据
const saveQifaTwoPath = {
  [RouteType.consumer]: "/goods-config/consumerProperty/sale-property-update/update-val", //消费品
  [RouteType.industrial]: "/goods-config/mroProperty/sale-property-update/update-val", //工业品
  [RouteType.food]: "/goods-config/foodProperty/sale-property-update/update-val" //食品
};

 

 //企发销售下载导入模板
export const downTempleteApi = (type: RouteType,params: FormData) =>
  http.download(`${PORT1}${downloadTemplatePath[type]}`, params, { cancel: false });

//企发销售下载失败文件
export const downFailTempleteApi = (type: RouteType,params: FormData) =>
  http.download(`${PORT1}${downloadFailTemplatePath[type]}`, params, { cancel: false });



//清关下载导入模板
export const downTempleteClearApi = (type: RouteType,params: FormData) =>
  http.download(`${PORT1}${downloadTemplateClearPath[type]}`, params, { cancel: false });

//清关下载失败文件
export const downFailTempleteClearApi = (type: RouteType,params: FormData) =>
  http.download(`${PORT1}${downloadFailTemplateClearPath[type]}`, params, { cancel: false });



//企发编辑属性
export const editGoodsProperty = (type: RouteType, params?: any) => {
  return http.post<{ [k: string]: any[] }>(`${PORT1}${EditsPath[type]}`, params, { loading: false });
};
//清关编辑属性
export const editClearancGoodsProperty = (type: RouteType, params?: any) => {
  return http.post<{ [k: string]: any[] }>(`${PORT1}${ClearancEditsPath[type]}`, params, { loading: false });
};
//新增企发销售属性
export const addClearancGoodsProperty = (type: RouteType, params?: any) => {
  return http.post<{ [k: string]: any[] }>(`${PORT1}${ClearancAddPath[type]}`, params, { loading: false });
};

//商品属性列表页树状图
export const getDailyNecessitiesTree = (type: RouteType, queueId?: string) =>
  http.get<TreeType[]>(`${PORT1}${TreePath[type]}`, {}, { queueId, loading: false });

// 属性值列表
export const getAttributeList = {
  [TabType.sales]: (type: RouteType, prop_id: string | number, type_id: string | number) =>
    http.post<{ table_id: string; table_data: { list: AttributeType[] } }>(
      `${PORT1}${SalesAttributeListPath[type]}`,
      { prop_id, type_id },
      { loading: false }
    ),
  [TabType.clearance]: (type: RouteType, cc_prop_id: string | number, type_id: string | number) =>
    http.post<{ table_id: string; table_data: { list: AttributeType[] } }>(
      `${PORT1}${ClearanceAttributeListPath[type]}`,
      { cc_prop_id, type_id },
      { loading: false }
    )
};

// 删除企发销售属性
export const deleteSalesProperty = (type: RouteType, prop_id: string | number, type_id: string | number) =>
  http.get<AttributeType[]>(`${PORT1}${DeleteSalesPropertyPath[type]}`, { prop_id, type_id }, { loading: false });

// 删除清关属性
export const deleteClearanceProperty = (type: RouteType, cc_prop_id: string | number, type_id: string | number) =>
  http.get<AttributeType[]>(`${PORT1}${DeleteClearancePropertyPath[type]}`, { cc_prop_id, type_id }, { loading: false });

// 企发销售下拉选项
export const getSalesOptions = (key: string) =>
  http.post<OptionType[]>(`${PORT1}/goods-config/consumerProperty/sale-property/search-item`, { key }, { loading: false });

// 清关属性下拉选项
export const getClearanceOptions = (key: string) =>
  http.post<OptionType[]>(`${PORT1}/goods-config/consumerProperty/cc-property/search-item`, { key }, { loading: false });

// 复制商品属性 start

// 获取商品类型
export const getProductTypeBySales = (type: RouteType) =>
  http.get<StandOptionType[]>(`${PORT1}${SalesProductType[type]}`, {}, { loading: false });
// 清关
export const getProductTypeByClearance = (type: RouteType) =>
  http.get<StandOptionType[]>(`${PORT1}${ClearanceProductType[type]}`, {}, { loading: false });

// 获取商品属性
export const getGoodsAttribute = {
  [TabType.sales]: (type: RouteType, type_id: number | string) =>
    http.post<StandOptionType[]>(`${PORT1}${SalesGoodsAttribute[type]}`, { type_id }, { loading: false }),
  [TabType.clearance]: (type: RouteType, type_id: number | string) =>
    http.post<StandOptionType[]>(`${PORT1}${ClearanceGoodsAttribute[type]}`, { type_id }, { loading: false })
};

// 复制商品属性
export const copyGoodsAttribute = {
  [TabType.sales]: (type: RouteType, type_id: number | string, new_type_id: number | string, prop: Array<number | string>) =>
    http.post(`${PORT1}${SalesCopyGoodsAttribute[type]}`, { type_id, new_type_id, prop }, { loading: false }),
  [TabType.clearance]: (type: RouteType, type_id: number | string, new_type_id: number | string, prop: Array<number | string>) =>
    http.post(`${PORT1}${ClearanceCopyGoodsAttribute[type]}`, { type_id, new_type_id, prop }, { loading: false })
};

// 复制商品属性 end

// 表格行内编辑
export const editCell = {
  [TabType.sales]: (type: RouteType, data: Record<string, any>) =>
    http.post(`${PORT1}${SalesEditCellPath[type]}`, data, { loading: false }),
  [TabType.clearance]: (type: RouteType, data: Record<string, any>) =>
    http.post(
      `${PORT1}${saveClearancOnePath[type]}`,
      { id: data.prop_id, prop: { [data.attribute]: data.value } },
      { loading: false }
    )
};

//清关编辑提交 俩块
export const saveClearancOne = (type: RouteType, params?: any) => {
  return http.post<{ [k: string]: any[] }>(`${PORT1}${saveClearancOnePath[type]}`, params, { loading: false });
};
export const saveClearancTwo = (type: RouteType, params?: any) => {
  return http.post<{ [k: string]: any[] }>(`${PORT1}${saveClearancTwoPath[type]}`, params, { loading: false });
};

//企发编辑提交 俩块
export const saveQifaOne = (type: RouteType, params?: any) => {
  return http.post<{ [k: string]: any[] }>(`${PORT1}${saveQifaOnePath[type]}`, params, { loading: false });
};
export const saveQifaTwo = (type: RouteType, params?: any) => {
  return http.post<{ [k: string]: any[] }>(`${PORT1}${saveQifaTwoPath[type]}`, params, { loading: false });
};

//企发编辑属性
export const addGoodsProperty = (type: RouteType, params?: any) => {
  return http.post<{ [k: string]: any[] }>(`${PORT1}${AddPath[type]}`, params, { loading: false });
};




























// 合并属性
// 获取左侧筛选列表
export const getLeftApi = (params: FormData) => {
  return http.get(PORT1 + `/goods-config/mergeProp/list/filter-option-list`, params, { cancel: false, loading: false });
};
export const getmergeDataApi = (params: FormData) => {
  return http.get(PORT1 + `/goods-config/mergeProp/list/list?get_auth=1&auth_name=mergeStats`, params, { cancel: false, loading: false });
};
// 表头
export const getmergfieldApi = (params: FormData) => {
  return http.get(PORT1 + `/goods-config/mergeProp/list/field`, params, { cancel: false, loading: false });
};
// 行内编辑
export const updatamergfieldApi = (params: FormData) => {
  return http.get(PORT1 + `/goods-config/mergeProp/list/update`, params, { cancel: false, loading: false });
};
// 枚举值弹框
export const gatEnmuApi = (params: FormData) => {
  return http.get(PORT1 + `/goods-config/mergeProp/list/enum-list`, params, { cancel: false, loading: false });
};
// 枚举值删除
export const mergePropdelete = (params: FormData) => {
  return http.get(PORT1 + `/goods-config/mergeProp/list/delete`, params, { cancel: false, loading: false });
};

